﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QLTour.Ultilities;
using QLTour.Biz;
using System.Data.SqlClient;
using System.Data;
namespace QLTour.Dal
{
    class GiaTourDal
    {
        DatabaseHelper db = new DatabaseHelper();
        
        public List<GiaTourBiz> GetListByTour(string matour)
        {
            List<GiaTourBiz> list = new List<GiaTourBiz>();
            SqlDataReader reader = db.Reader("SELECT * FROM [GiaTour] WHERE [MaTour]='"+matour+"'");
            while (reader.Read())
            {
                GiaTourBiz giatour = new GiaTourBiz();
                giatour.MaGia = int.Parse(reader["MaGia"].ToString());
                giatour.Ten = reader["Ten"].ToString();
                giatour.BatDau = (DateTime)reader["BatDau"];
                giatour.KetThuc = (DateTime)reader["KetThuc"];
                giatour.DangApDung = (bool)reader["DangApDung"];
                giatour.MaTour = matour;
                list.Add(giatour);
            }
            return list;
        }
        public Boolean Insert(GiaTourBiz giatour)
        {
            DatabaseHelper db = new DatabaseHelper();
            string query=   "INSERT INTO dbo.[GiaTour]([Ten],[BatDau],[KetThuc],[DangApDung],[MaTour],[GiaTri])" +
                            "VALUES (N'" + giatour.Ten + "','" + giatour.BatDau + "','" + giatour.KetThuc + "','" + giatour.DangApDung + "','" + giatour.MaTour + "','"+giatour.GiaTri+"')";
            int rs = db.ExecuteNonQuery(query);
            return rs > 0;
        }
        public Boolean Update(GiaTourBiz giatour)
        {
            DatabaseHelper db = new DatabaseHelper();
            string query = " UPDATE [GiaTour]" +
                           " SET [Ten] =  N'" + giatour.Ten + "'," +" [GiaTri] =  N'" + giatour.GiaTri + "',"+" [BatDau] =  N'" + giatour.BatDau + "',"+" [KetThuc] =  N'" + giatour.KetThuc + "'"+
                           " WHERE [MaGia] = N'" + giatour.MaGia + "'";
            int rs = db.ExecuteNonQuery(query);
            return rs > 0;
        }
    }
}
